/*******************************************************************************
 *  Copyright (c) 2017 Oliver Meili
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Eclipse Distribution License v1.0 which accompany this distribution.
 *   
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  The Eclipse Distribution License is available at
 *  http://www.eclipse.org/org/documents/edl-v10.php.
 *   
 *  Contributors:
 *  Oliver Meili <omi@ieee.org>
 *******************************************************************************/
package org.eclipse.vorto.codegen.ble.alpwise.templates

import java.io.File
import org.eclipse.vorto.codegen.api.InvocationContext
import org.eclipse.vorto.codegen.ble.model.blegatt.Service
import org.eclipse.vorto.codegen.ble.templates.BleGattTemplate

class AlpwiseServiceHeaderTemplate extends BleGattTemplate<Service> {
	
	override getFileName(Service service) {
		return service.name + "Service.h";
	}
	
	override getPath(Service service) {
		return rootPath + File.separator + "services";
	}
	
	override getContent(Service service, InvocationContext context) {
'''
/* «service.name»Service generated by Vorto */

#ifndef __«service.name.toUpperCase»_SERVICE_H__
#define __«service.name.toUpperCase»_SERVICE_H__

#include <stdint.h>
#include <AttBase.h>

#include "BleUtils.h"

#define ENABLE_«service.name.toUpperCase»_SERVICE_NOTIFICATIONS 1
#define NUM_«service.name.toUpperCase»_SERVICES         1

// Configuration per service instance
typedef struct _«service.name»Service_t {

	uint8_t uuid[16];
	AttServiceAttribute ServiceHandle; /** Attribute handle for the service */

	// Configuration and status per characteristic
	«FOR ch : service.characteristics»
		characteristicProperty_t   «ch.name.toFirstUpper»;
		uint8_t                    «ch.name.toFirstUpper»Value[«ch.length»];
	«ENDFOR»
	
} «service.name»Service_t;

«service.name»Service_t «service.name»Service_Instances[NUM_«service.name.toUpperCase»_SERVICES];

void «service.name»Service_Init(void);
void «service.name»Service_WriteAndNotifyValue(characteristicProperty_t *ch, uint8_t *value, uint8_t length, uint8_t notify);

#endif /* __«service.name.toUpperCase»_SERVICE_H__ */
'''
	}
	
}
